#include "TinyJsonValue.h"
#include "TinyJsonReader.h"
#include "UnitTest.h"
#include "Log.h"
using namespace tinyjson;

int main()
{
    LogHandler loghandler("logs/tinyjson.log");
    //单元测试
    UnitTest::instance().test_all();

    //解析器
    TinyJsonReader reader;
    reader.load_from_string("{ \"a\" : \"1234\", \"ooo\" : { \"aa\" : 123, \"bbb\" : null, \"ccc\" : {} } }");
    // reader.load_from_file("json/example1.txt");
    reader.parse();
    if (TinyJsonParseRet::TINY_JSON_PARSE_FAIL == reader.parse_state())
    {
        SPDLOG_LOGGER_ERROR(spdlog::get("spdlog"),"Parse fail!");
        return -1;
    }
    TinyJsonValue value1 = reader.parse_result();
    SPDLOG_LOGGER_DEBUG(spdlog::get("spdlog"),"{}",value1);

    reader.load_from_file("json/example2.txt");
    reader.parse();
    if (TinyJsonParseRet::TINY_JSON_PARSE_FAIL == reader.parse_state())
    {
        SPDLOG_LOGGER_ERROR(spdlog::get("spdlog"),"Parse fail!");
        return -1;
    }
    TinyJsonValue value2 = reader.parse_result();
    SPDLOG_LOGGER_DEBUG(spdlog::get("spdlog"),"{}",value2);

    //生成器
    TinyJsonWriter writer;
    writer.push(value1);
    writer.write("json/output1.txt");

    writer.push(value2);
    writer.write("json/output2.txt");

    return 0;
}